package cn.ffcs.uec.post.component;

import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Bandbox;

import cn.ffcs.uec.post.vo.BasePostVo;
import cn.ffcs.uom.common.zkplus.zul.tree.node.impl.TreeNodeImpl;

public class BasePostTreeBandboxExt extends Bandbox implements IdSpace {
	private static final long serialVersionUID = -2300600253537546936L;
	
	private final String zul = "/pages_nmg/uec_post/comp/base_post_tree_bandbox_ext.zul";
	
	/**
	 * 选择的基准岗位
	 */
	private BasePostVo basePostVo;
	
	/**
	 * 基准岗位树
	 */
	private BasePostTree basePostTree;
	
	public BasePostTreeBandboxExt() {
		Executions.createComponents(this.zul, this, null);
		Components.wireVariables(this, this);
		Components.addForwards(this, this, '$');
		this.init();
	}
	
	/**
	 * 界面初始化.
	 */
	public void init() {
		this.setReadonly(true);
		this.basePostTree.addEventListener(Events.ON_SELECT,
				new EventListener() {
					@SuppressWarnings("rawtypes")
					public void onEvent(Event event) throws Exception {
						if (BasePostTreeBandboxExt.this.basePostTree
								.getSelectedCount() > 0) {
							Object data = BasePostTreeBandboxExt.this.basePostTree
									.getSelectedItem().getValue();
							BasePostTreeBandboxExt.this
									.setBasePostVo((BasePostVo) ((TreeNodeImpl) data)
											.getEntity());
						}
						BasePostTreeBandboxExt.this.close();
					}
				});
	}
	
	public Object getAssignObject() {
		return getBasePostVo();
	}
	
	public void setAssignObject(Object assignObject) {
		if (assignObject == null || assignObject instanceof BasePostVo) {
			setBasePostVo((BasePostVo) assignObject);
		}
	}

	public BasePostVo getBasePostVo() {
		return this.basePostVo;
	}

	public void setBasePostVo(BasePostVo basePostVo) {
		this.setValue(basePostVo == null ? "" : basePostVo.getPostname());
		this.basePostVo = basePostVo;
		Events.postEvent("onGetBasePost",this, basePostVo);
	}
}
